#include "convert.h"

GEO_ALG_BEGIN_NAMESPACE


MultiSurface box_surface(const Box3d& box) {
    MultiSurface multi_surface;
    if (!box.is_valid()) {
        return multi_surface;
    }
    Point3d p1, p2, p3, p4; //bottom points
    Point3d p5, p6, p7, p8;//top points

    p1 = box.min_;
    p2 = box.min_;
    p2.x_ = box.max_.x_;
    p3 = box.max_;
    p3.z_ = box.min_.z_;
    p4 = box.min_;
    p4.y_ = box.max_.y_;

    p5 = box.min_;
    p5.z_ = box.max_.z_;
    p6 = p2;
    p6.z_ = box.max_.z_;
    p7 = box.max_;
    p8 = p4;
    p8.z_ = box.max_.z_;

    Surface f1;
    f1.normal_ = Vector3d(0, 0, -1);
    f1.borders_ << p1 << p2 << p3 << p4;


    Surface f2;
    f2.normal_ = Vector3d(0, -1, 0);
    f2.borders_ << p1 << p2 << p6 << p5;

    Surface f3;
    f3.normal_ = Vector3d(1, 0, 0);
    f3.borders_ << p2 << p3 << p7 << p6;
    Surface f4;
    f4.normal_ = Vector3d(0, 1, 0);
    f4.borders_ << p3 << p4 << p8 << p7;

    Surface f5;
    f5.normal_ = Vector3d(-1, 0, 0);
    f5.borders_ << p4 << p1 << p5 << p8;

    Surface f6;
    f6.normal_ = Vector3d(0, 0, 1);
    f6.borders_ << p5 << p6 << p7 << p8;

    multi_surface.push_back(f1);
    multi_surface.push_back(f2);
    multi_surface.push_back(f3);
    multi_surface.push_back(f4);
    multi_surface.push_back(f5);
    multi_surface.push_back(f6);
    return multi_surface;
}

GEO_ALG_END_NAMESPACE